<?php
namespace app\api\logic;
use think\Db;
class Store extends Base{

    private $AccountInfo = [];

    public function __construct()
    {
        parent::__construct();
    }

    //门店页信息
    public function storeInfo($param)
    {
        $sid = isset($param['sid'])?intval($param['sid']):0;
        $info= Db::name('store')->where([['id','=',$sid],['status','=',1]])->find();
        if (!$info){
            $this->return_data['Msg'] = "门店过期或无此门店";
            return $this->return_data;
        }

        $store_teachers = Db::name('teacher')->where([['sid','=',$sid],['status','=',1]])->order('ordernum asc,id desc')->select();
        foreach($store_teachers as $k=>$v){
          $store_teachers[$k]['cover'] = get_basecover_img($v['avatar']);
          $store_teachers[$k]['wxcode'] = get_basecover_img($v['wxcode']);
        }
        $store_courses = Db::name('course')->where([['sid','=',$sid],['status','=',1],['isindex','=',1]])->order('ordernum asc,id desc')->select();
        foreach($store_courses as $k=>$v){
          $store_courses[$k]['cover'] = get_newpic_url($v['pic']);
        }

        /*
        $store_photos = Db::name('store_photo')->where([['sid','=',$sid]])->select();
        $pts = [];
        foreach($store_photos as $v){
          $pts[] = get_newpic_url($v['path']);
        }
         */
        //$info['store_photos'] = $pts;
        $info['pics1'] = '';
        if($info['pic1'])
          $info['pics1'] = get_newpic_url($info['pic1']);
        $info['pics2'] = '';
        if($info['pic2'])
          $info['pics2'] = get_newpic_url($info['pic2']);
        $info['pics3'] = '';
        if($info['pic3'])
          $info['pics3'] = get_newpic_url($info['pic3']);

        $info['vpics1'] = '';
        if($info['vpic1'])
          $info['vpics1'] = get_newpic_url($info['vpic1']);
        $info['vpics2'] = '';
        if($info['vpic2'])
          $info['vpics2'] = get_newpic_url($info['vpic2']);
        $info['vpics3'] = '';
        if($info['vpic3'])
          $info['vpics3'] = get_newpic_url($info['vpic3']);

        $info['wxcode'] = get_basecover_img($info['wxcode']);
        
        $activity = Db::name('activity')->where([['status','=',1],['sid','=',$sid]])->find();
        $activity['cover'] = '';
        if(isset($activity['pic']))
          $activity['cover'] = get_newpic_url($activity['pic']); 
        $appointing = Db::name('appointing')->where([['sid','=',$sid]])->limit(20)->select();

        // 门店集合
        if ($info['is_group']==1) {
          $address = explode(',', $info['address']);
          $group_store = explode(',', $info['group_store']);
          $info['group_store_arr'] = [];
          if (count($group_store)) {
            foreach ($group_store as $key => $value) {
              $info['group_store_arr'][] = ['name'=>$value,'address'=>isset($address[$key])?$address[$key]:''];
            }
          }
        }

        $this->return_data["Code"] = 0;
        $this->return_data["Data"] = ['teachers'=>$store_teachers,'store'=>$info,'activity'=>$activity,'courses'=>$store_courses,'appointing'=>$appointing];
        return $this->return_data;
    }

}
